var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/query-panel/index.tsx
var query_panel_exports = {};
__export(query_panel_exports, {
  QueryPanel: () => QueryPanel
});
module.exports = __toCommonJS(query_panel_exports);
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_react = require("react");
var import_react_dom = __toESM(require("react-dom"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_grid = require("../grid");
var import_help = require("../help");
var import_service = require("./service");
var import_index = require("./index.less");
var defaultShowRowCount = 1;
var defaultLocale = {
  title: "查询",
  search: "查询",
  reset: "重置",
  up: "收起",
  down: "更多",
  rememberCheckbox: "记忆搜索",
  settingTitle: "查询设置",
  settingCondition: "条件设置",
  settingScheme: "方案设置",
  resetText: "恢复默认",
  okText: "确认",
  cancelText: "取消",
  settingText: "设置",
  queryScheme: "查询方案",
  confirmText: "恢复默认将会删除该页面内嵌查询自己修改过的所有数据，确认恢复默认吗？"
};
var operatorType = {
  eq: "=",
  gt: ">",
  lt: "<",
  ge: ">=",
  le: "<=",
  like: "%*%",
  LLike: "*%",
  RLike: '"%*'
};
var getSettingConditionCfg = ({ hiddenTableField }) => ({
  busKey: "id",
  columns: [
    {
      header: "表名",
      dataIndex: "searchTable",
      hidden: hiddenTableField
    },
    {
      header: "字段",
      dataIndex: "searchField",
      hidden: hiddenTableField
    },
    {
      header: "字段名称",
      dataIndex: "fieldNameChn"
    },
    {
      header: "运算符",
      dataIndex: "operator",
      width: 70,
      render: function({ row }) {
        return operatorType[row.operator] || row.operator;
      }
    },
    {
      header: "布局顺序",
      dataIndex: "displayIndex",
      width: 75,
      editor: {
        xtype: "InputNumber",
        min: 0
      }
    },
    {
      header: "列占比",
      dataIndex: "colSpan",
      width: 75,
      hidden: true,
      editor: {
        xtype: "InputNumber",
        min: 1,
        step: 1,
        max: 4
      }
    },
    {
      header: "是否显示",
      dataIndex: "displayFlg",
      width: 80,
      align: "center",
      editor: {
        xtype: "checkbox",
        antProps: { checkedValue: 1, unCheckedValue: 0 }
      }
    }
  ],
  busFields: [
    "id",
    "bizCode",
    "pageId",
    "searchTable",
    "searchField",
    "fieldNameChn",
    "fieldType",
    "operator",
    "defaultdata",
    "displayIndex",
    "colSpan",
    "displayFlg",
    "remark"
  ]
});
function SettingFooter({ locale }) {
  const ctx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const [loading, setLoading] = (0, import_react.useState)({ reset: false, ok: false });
  const [tabKey, setTabKey] = (0, import_react.useState)("settingCondition" /* tab1 */);
  const refreshQueryPanel = (value = "panel") => {
    ctx.ins.notify(value, "updateRefresh").then();
    ctx.ins.destroy();
  };
  const resetClick = () => {
    setLoading((pre) => ({ ...pre, reset: true }));
    (0, import_service.resetQuerySettingInfo)({ pageId: ctx.params.pageId }).then(() => {
      refreshQueryPanel();
    });
  };
  const okClick = async () => {
    const { key, isChanged, result, schemeId } = ctx.ins.getApi().getResult();
    if (isChanged) {
      if (key === "settingCondition" /* tab1 */) {
        if (await (0, import_service.saveQuerySettingInfo)({
          pageId: ctx.params.pageId,
          data: result
        })) {
          refreshQueryPanel();
        }
      } else {
        if (await (0, import_service.saveQuerySchemeData)({
          schemeId,
          data: result
        })) {
          refreshQueryPanel("scheme");
        }
      }
    } else {
      ctx.ins.destroy();
    }
  };
  ctx.ins.setApi({
    switchTab(key) {
      setTabKey(key);
    }
  });
  const buttonProps = {
    style: { marginLeft: 10, minWidth: 68 }
  };
  return /* @__PURE__ */ React.createElement(
    "div",
    {
      style: {
        display: "flex",
        alignItems: "center",
        justifyContent: "flex-end",
        padding: "16px"
      }
    },
    tabKey === "settingCondition" /* tab1 */ && /* @__PURE__ */ React.createElement(
      import_antd.Popconfirm,
      {
        title: locale.confirmText,
        okText: locale.okText,
        cancelText: locale.cancelText,
        placement: "topRight",
        onConfirm: resetClick
      },
      /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { loading: loading.reset, ...buttonProps }, locale.resetText)
    ),
    /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { ...buttonProps, onClick: () => ctx.ins.destroy() }, locale.cancelText),
    /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { ...buttonProps, type: "primary", onClick: okClick }, locale.okText)
  );
}
function SettingContent({ locale, hiddenTableField }) {
  const ctx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const { pageId } = ctx.params;
  const [getRef, removeRef] = (0, import_util.useRefs)();
  const varRef = (0, import_react.useRef)({
    tabKey: "settingCondition" /* tab1 */,
    schemeUpdate: false
  });
  const buttons = (0, import_react.useMemo)(
    () => [
      "add",
      "delete",
      { id: "u_start", hidden: true, text: "启用", icon: /* @__PURE__ */ React.createElement(import_icons.CheckCircleOutlined, null) },
      { id: "u_stop", hidden: true, text: "停用", icon: /* @__PURE__ */ React.createElement(import_icons.PauseCircleOutlined, null) }
    ],
    []
  );
  const [scheme, setScheme] = (0, import_react.useState)({});
  const schemeId = scheme.key;
  const conditionRequest = (0, import_util.useRefCallback)(async () => await (0, import_service.getQuerySettingInfo)({ pageId }));
  const treeRequest = (0, import_util.useRefCallback)(async () => await (0, import_service.getQuerySchemeTree)({ pageId }));
  const schemeRequest = (0, import_react.useCallback)(() => (0, import_service.getQuerySchemeData)({ schemeId }), [schemeId]);
  const onTbClick = (0, import_util.useRefCallback)(async ({ id, toolbar }) => {
    const successCallback = (update = true) => {
      const treeApi = getRef("treeRef").current.getApi();
      varRef.current.schemeUpdate = update;
      treeApi.refresh();
    };
    switch (id) {
      case "add":
        const schemeName = await new Promise((resolve) => {
          const InnerInput = () => {
            const [status, setStatus] = (0, import_react.useState)("");
            const onInputChange = (value) => {
              setStatus(value ? "" : "error");
            };
            (0, import_util.useExtendRef)(getRef("schemeName"), () => {
              return { setStatus };
            });
            (0, import_react.useEffect)(() => {
              return () => removeRef("schemeName");
            }, []);
            return /* @__PURE__ */ React.createElement(import_baseComponent.Input, { ref: getRef("schemeName"), size: "large", onChange: onInputChange, status });
          };
          (0, import_functionalComponent.showModal)({
            title: "新增-方案名称",
            width: 360,
            contentStyle: { padding: "15px 20px" },
            content: /* @__PURE__ */ React.createElement(InnerInput, null),
            okText: "确定",
            cancelText: "取消",
            closable: false,
            onOk: (ins) => {
              const inputApi = getRef("schemeName").current.getApi();
              const name = inputApi.getValue();
              if (name) {
                ins.destroy();
                resolve(name);
              } else {
                inputApi.setStatus("error");
              }
            },
            onCancel: (ins) => {
              ins.destroy();
              resolve(false);
            }
          });
        });
        if (schemeName) {
          if (await (0, import_service.addQueryScheme)({ schemeName, pageId })) {
            successCallback();
          }
        }
        break;
      case "delete":
        if (!schemeId) {
          return await import_util.iup.alert("请先选择方案！");
        }
        if (!await import_util.iup.confirm("确认删除方案？")) {
          return;
        }
        if (await (0, import_service.deleteQueryScheme)({ schemeId })) {
          setScheme({});
          successCallback();
        }
        break;
      case "u_start":
        if (await (0, import_service.updateQuerySchemeStatus)({ schemeId, status: 1 })) {
          successCallback();
        }
        break;
      case "u_stop":
        if (await (0, import_service.updateQuerySchemeStatus)({ schemeId, status: 0 })) {
          successCallback();
        }
        break;
      default:
        break;
    }
  });
  const onTreeSelectedChange = (0, import_util.useRefCallback)((keys, nodes) => {
    setScheme(nodes[0]);
  });
  ctx.ins.setApi({
    getResult() {
      const api = getRef(varRef.current.tabKey).current.getApi();
      if (varRef.current.tabKey === "settingCondition" /* tab1 */) {
        return {
          key: varRef.current.tabKey,
          isChanged: api.isChanged(),
          result: api.getRows()
        };
      } else {
        return {
          key: varRef.current.tabKey,
          schemeId,
          isChanged: varRef.current.schemeUpdate || api.isChanged(),
          result: api.getRows()
        };
      }
    }
  });
  const tabTitle = (title) => /* @__PURE__ */ React.createElement("span", { style: { padding: "0 5px" } }, title);
  (0, import_react.useEffect)(() => {
    var _a, _b, _c;
    if (scheme.key) {
      const status = (_a = scheme.title) == null ? void 0 : _a.endsWith("(停)");
      (_b = getRef("schemeTb").current) == null ? void 0 : _b.getApi().setHidden("u_start", !status);
      (_c = getRef("schemeTb").current) == null ? void 0 : _c.getApi().setHidden("u_stop", status);
    }
  }, [scheme]);
  return /* @__PURE__ */ React.createElement(
    import_functionalComponent.Tabs,
    {
      tabBarGutter: 20,
      onChange: (key) => {
        varRef.current.tabKey = key;
        ctx.ins.getApi().switchTab(key);
      },
      items: [
        {
          label: tabTitle(locale.settingCondition),
          key: "settingCondition" /* tab1 */,
          children: /* @__PURE__ */ React.createElement(
            import_grid.Grid,
            {
              ref: getRef("settingCondition" /* tab1 */),
              bordered: true,
              headerMenu: false,
              request: conditionRequest,
              ...getSettingConditionCfg({ hiddenTableField }),
              style: { borderTop: 0 }
            }
          )
        }
        //,
        // {
        //   label: tabTitle(locale.settingScheme),
        //   key: TabKeyEnum.tab2,
        //   children: (
        //     <Layout direction="column" autoFit>
        //       <ToolBar
        //         onClick={onTbClick}
        //         ref={getRef('schemeTb')}
        //         style={{ borderBottom: `1px solid ${cssVar.borderColorSplit}`, height: 40 }}
        //         buttons={buttons}
        //       />
        //       <Layout.Flex direction="row">
        //         <Layout.Slider size={180} style={{ borderBottom: `1px solid ${cssVar.borderColorSplit}` }}>
        //           <AsyncTree
        //             request={treeRequest}
        //             nowrap={false}
        //             defaultChange
        //             ref={getRef('treeRef')}
        //             onSelectedChange={onTreeSelectedChange}
        //             showFilter={false}
        //           />
        //         </Layout.Slider>
        //         <Layout.Flex>
        //           <Grid
        //             bordered={true}
        //             ref={getRef(TabKeyEnum.tab2)}
        //             request={schemeRequest}
        //             {...settingSchemeCfg}
        //             style={{ borderTop: 0 }}
        //           />
        //         </Layout.Flex>
        //       </Layout.Flex>
        //     </Layout>
        //   )
        // }
      ]
    }
  );
}
function filterProps(fp, props) {
  if (fp) {
    const { antProps, ...others } = fp;
    return { ...props, ...others, ...antProps };
  }
  return props;
}
function getInput({ formId, field: originField, fieldInput, fieldProps }, disabled = false, placeholder) {
  if (fieldInput) {
    const node = fieldInput(originField, disabled, placeholder);
    if (node) {
      return node;
    }
  }
  const fp = fieldProps[originField.itemId] || fieldProps[originField.name] || {};
  if (originField.hasOwnProperty("ormMode")) {
    originField.ORMMode = originField.ormMode;
  }
  const field = {
    ...originField,
    ...import_util.iup.isFunction(fp) ? fp(originField) : fp
  };
  const baseProps = {
    id: field.name || field.itemId || field.id,
    disabled,
    ...filterProps(fp, field.antProps)
  };
  const commonProps = {
    placeholder: field.placeholder ?? placeholder,
    ...baseProps,
    allowClear: true
  };
  [
    "request",
    "params",
    "showTime",
    "renderExtraFooter",
    "disabledTime",
    "input",
    "multiple",
    "params",
    "modal"
  ].forEach((key) => {
    if (!commonProps.hasOwnProperty(key) && field.hasOwnProperty(key)) {
      commonProps[key] = field[key];
    }
  });
  switch (field.xtype) {
    case "Select":
      return /* @__PURE__ */ React.createElement(
        import_baseComponent.Select,
        {
          data: field.data,
          valueField: field.valueField || "value",
          labelField: field.displayField || "label",
          ...commonProps
        }
      );
    case "SingleHelp":
      return /* @__PURE__ */ React.createElement(
        import_help.SingleHelp,
        {
          helpId: field.helpId || field.helpid,
          clientSqlFilter: field.clientSqlFilter,
          valueField: field.valueField,
          displayField: field.displayField,
          userCodeField: field.usercodeField || field.userCodeField,
          ...commonProps
        }
      );
    case "MultipleHelp":
      return /* @__PURE__ */ React.createElement(
        import_help.MultipleHelp,
        {
          helpId: field.helpId || field.helpid,
          clientSqlFilter: field.clientSqlFilter,
          valueField: field.valueField,
          displayField: field.displayField,
          userCodeField: field.usercodeField || field.userCodeField,
          ...commonProps
        }
      );
    case "DatePicker":
      return /* @__PURE__ */ React.createElement(import_baseComponent.DatePicker, { picker: field.picker, ...commonProps });
    case "DateTimePicker":
      return /* @__PURE__ */ React.createElement(import_baseComponent.DatePicker, { picker: field.picker, ...commonProps, showTime: true });
    case "RangePicker":
    case "DateRangePicker":
      return /* @__PURE__ */ React.createElement(import_baseComponent.RangePicker, { allowEmpty: field.allowEmpty || [true, true], picker: field.picker, ...commonProps });
    case "TimeRangePicker":
    case "DateTimeRangePicker":
      return /* @__PURE__ */ React.createElement(import_baseComponent.RangePicker, { allowEmpty: field.allowEmpty || [true, true], picker: field.picker, ...commonProps, showTime: true });
    case "InputNumberRange":
      return /* @__PURE__ */ React.createElement(
        import_baseComponent.InputNumberRange,
        {
          step: field.step,
          precision: field.decimalPrecision,
          decimalSeparator: field.decimalSeparator,
          ...commonProps
        }
      );
    case "InputNumber":
      return /* @__PURE__ */ React.createElement(
        import_baseComponent.InputNumber,
        {
          step: field.step,
          precision: field.decimalPrecision,
          decimalSeparator: field.decimalSeparator,
          ...commonProps
        }
      );
    case "Switch":
      return /* @__PURE__ */ React.createElement(import_baseComponent.Switch, { ...baseProps });
    case "Checkbox":
      return /* @__PURE__ */ React.createElement(import_baseComponent.Checkbox, { ...baseProps });
    case "CheckboxGroup":
      return /* @__PURE__ */ React.createElement(import_baseComponent.CheckboxGroup, { options: field.data, ...commonProps });
    case "RadioGroup":
      return /* @__PURE__ */ React.createElement(import_baseComponent.RadioGroup, { options: field.data, ...commonProps });
    default: {
      if (import_util.iup.isFunction(field.xtype)) {
        const FieldComp = field.xtype;
        return /* @__PURE__ */ React.createElement(FieldComp, { ...commonProps });
      }
      const [instance, defaultProps, extendObj] = (0, import_util.getRegisterComponentWithProps)(field.xtype);
      const { instance: Comp } = { instance: instance || import_baseComponent.Input };
      field.hasOwnProperty("clientSqlFilter") && (defaultProps.clientSqlFilter = field.clientSqlFilter);
      field.hasOwnProperty("valueField") && (defaultProps.valueField = field.valueField);
      field.hasOwnProperty("displayField") && (defaultProps.displayField = field.displayField);
      field.hasOwnProperty("usercodeField") && (defaultProps.userCodeField = field.usercodeField);
      field.hasOwnProperty("typeCode") && (defaultProps.typeCode = field.typeCode);
      return /* @__PURE__ */ React.createElement(Comp, { ...defaultProps, ...commonProps });
    }
  }
}
function getValueFromArray(values) {
  if (import_util.iup.isArray(values)) {
    return values.length > 0 ? values.map((item) => {
      return (item == null ? void 0 : item.hasOwnProperty("value")) ? item.value ?? "" : item;
    }) : void 0;
  }
  return values;
}
function convertFormValues(values) {
  const handleDate = (key, value) => {
    if (import_util.iup.isString(value)) {
      value = value.trim();
    }
    if (import_util.iup.isString(value) && key.indexOf("date*le") > -1 && (value == null ? void 0 : value.length) < 11) {
      key = key.replace("date*le", "date*lt");
      value = import_util.iup.addDate(value, 1, "date", "YYYY-MM-DD");
    }
    return [key, value];
  };
  return Object.keys(values).reduce((p, key) => {
    const kv = values[key];
    if (import_util.iup.isNullOrEmpty(kv) || import_util.iup.isArray(kv) && kv.length === 0) {
      return p;
    }
    if (key.indexOf(",") > 0 && import_util.iup.isArray(kv)) {
      const arr = key.split(",");
      kv.forEach((v, i) => {
        if (!import_util.iup.isNullOrEmpty(v)) {
          const [k, nv] = handleDate(arr[i], v);
          p[k] = nv;
        }
      });
    } else {
      let value = kv.hasOwnProperty("value") ? kv.value : getValueFromArray(kv);
      [key, value] = handleDate(key, value);
      p[key] = value;
    }
    return p;
  }, {});
}
function FiledLabel({ label }) {
  if (label) {
    const labelStyle = {
      display: "inline-block",
      color: "initial",
      textAlign: "right",
      wordBreak: "break-all",
      whiteSpace: "normal",
      maxHeight: "35px",
      lineHeight: 1.25
    };
    return /* @__PURE__ */ React.createElement(import_functionalComponent.Tooltip, { title: label, overflow: true }, /* @__PURE__ */ React.createElement("span", { style: labelStyle }, label));
  }
  return /* @__PURE__ */ React.createElement("span", null);
}
var buttonStyle = { marginLeft: 8 };
var QueryForm = (0, import_util.compHoc)(
  function({
    reader,
    ...others
  }) {
    const queryInfo = reader().data;
    const [props, fields] = (0, import_util.useDevState)({ type: "query", props: others, items: queryInfo.fields, itemKey: "name" });
    const {
      pageId,
      items,
      onSearch,
      onReset,
      onLoad,
      buttonProps,
      outRef,
      size = "default",
      readonlyItems = [],
      update,
      gridRef,
      fieldInput,
      fieldProps,
      showLabel = true,
      showAll = false,
      needRemember = true,
      hiddenTableField = true,
      needSetting = true,
      defaultExpand = false,
      columns = 4,
      values,
      onValuesChange,
      querySchemeContainer,
      id
    } = props;
    const chk = (0, import_react.useRef)();
    const getDisabled = (0, import_react.useCallback)(
      (field) => {
        return field.disabled || field.readonly || field.readOnly || readonlyItems.includes(field.itemId) || readonlyItems.includes(field.name);
      },
      [readonlyItems.join(",")]
    );
    const [form] = import_antd.Form.useForm();
    const computedDeps = (0, import_react.useRef)(/* @__PURE__ */ new Set());
    const [u, forceUpdate] = (0, import_react.useState)({});
    const defaultValues = (0, import_react.useMemo)(() => values || {}, [values]);
    const [expand, setExpand] = (0, import_react.useState)(defaultExpand || showAll);
    const [refreshScheme, setRefreshScheme] = (0, import_react.useState)({});
    const byItems = !!items;
    const memoObj = (0, import_react.useMemo)(() => {
      let initialValues;
      if (!needRemember || byItems) {
        initialValues = {};
      } else if (queryInfo.isChecked) {
        initialValues = queryInfo.values;
      } else {
        initialValues = fields.reduce((pre, field) => {
          return getDisabled(field) ? { ...pre, [field.name]: queryInfo.values[field.name] } : pre;
        }, defaultValues);
      }
      return {
        rememberValues: initialValues,
        fields,
        formId: props["data-cid"] || pageId || `form${Math.random().toString(32).slice(2)}`
      };
    }, [pageId, queryInfo, getDisabled, needRemember, fields, byItems]);
    const cacheValues = (0, import_react.useMemo)(
      () => ({ ...memoObj.rememberValues, ...defaultValues }),
      [memoObj.rememberValues, defaultValues]
    );
    const pageNotify = (0, import_util.useDebounce)(
      ({ type = "onValuesChange", params = {}, updateValue }) => {
        import_util.iup.getPageObserver().notify(
          {
            key: getObjPath(updateValue),
            containerId: memoObj.formId,
            form: outRef.current,
            instance: outRef.current,
            args: [updateValue, cacheValues],
            ...params
          },
          type
        );
      },
      { wait: 250 }
    );
    const syncValues = (changedValues, notify = false) => {
      Object.assign(cacheValues, changedValues);
      const changedKeys = Object.keys(changedValues);
      changedKeys.forEach((key) => {
        if (defaultValues.hasOwnProperty(key)) {
          defaultValues[key] = changedValues[key];
        }
      });
      if (computedDeps.current.size > 0) {
        const needUpdate = changedKeys.some((k) => computedDeps.current.has(k));
        needUpdate && forceUpdate({});
      }
      if (notify) {
        pageNotify({ updateValue: changedValues });
      }
    };
    (0, import_react.useEffect)(() => {
      form.setFieldsValue(cacheValues);
    }, [cacheValues]);
    const getGridApi = () => {
      var _a;
      const gridIns = import_util.iup.isString(gridRef) ? import_util.iup.getCmp(gridRef) : gridRef == null ? void 0 : gridRef.current;
      return (_a = gridIns == null ? void 0 : gridIns.getApi) == null ? void 0 : _a.call(gridIns);
    };
    const searchEvent = (0, import_util.useRefCallback)(async () => {
      let searchValues = outRef.current.getSearchValues();
      import_util.iup.debug(searchValues);
      if (onSearch) {
        const hookRet = await onSearch(outRef.current, searchValues);
        if (hookRet) {
          searchValues = { ...searchValues, ...hookRet };
        }
      }
      await new Promise((resolve) => {
        var _a;
        (_a = getGridApi()) == null ? void 0 : _a.query(searchValues || outRef.current.getSearchValues(), resolve);
      });
    });
    const rewriteFormApi = {
      setFieldsValue(values2) {
        syncValues(values2);
        form.setFieldsValue(values2);
      }
    };
    (0, import_util.useExtendRef)(outRef, {
      ...form,
      ...rewriteFormApi,
      getSearchValues: () => convertFormValues(form.getFieldsValue()),
      getItem: (name) => {
        var _a;
        return (_a = form.getFieldInstance(name)) == null ? void 0 : _a.getApi();
      },
      setFieldValue: (name, value) => rewriteFormApi.setFieldsValue({ [name]: value }),
      query: searchEvent,
      getQueryInfo() {
        return queryInfo;
      }
    });
    const onFinish = (values2) => {
      var _a;
      if (needRemember && !byItems) {
        (0, import_service.setQueryPanelData)({ pageId, values: values2, checked: (_a = chk.current) == null ? void 0 : _a.getApi().getValue() }).then();
      }
      searchEvent().then();
    };
    const convertItem = (0, import_util.useRefCallback)(({ computed, ...newItem }) => {
      if (import_util.iup.isFunction(computed)) {
        const formatValue = convertFormValues(cacheValues);
        if (computedDeps.current.size === 0) {
          const p1 = new Proxy(formatValue, {
            get(t, p) {
              computedDeps.current.add(p);
              return t[p];
            }
          });
          const p2 = new Proxy(formatValue, {
            get(t, p) {
              computedDeps.current.add(p);
              return t[p];
            }
          });
          import_util.iup.assign(newItem, computed(p1, p2));
        } else {
          import_util.iup.assign(newItem, computed(formatValue, cacheValues));
        }
      }
      return newItem;
    });
    const [totalColSpan, queryFields] = (0, import_react.useMemo)(() => {
      const { fields: fields2, formId } = memoObj;
      const fieldsCol = fields2.reduce((p, f) => (f.colSpan || f.colspan || 1) + p, 0);
      const col = fieldsCol > 3 ? columns : fieldsCol;
      const colStyle = fields2.length === 1 && (fields2[0].colSpan || fields2[0].colspan) !== 3 ? { maxWidth: "66%" } : {};
      const avgSpan = 24 / col;
      let showFieldCount = col * defaultShowRowCount;
      let tcs = 0;
      const allFields = fields2.map((originItem) => {
        const f = convertItem(originItem);
        const colspan = Math.min(col, f.colSpan || f.colspan || 1);
        showFieldCount -= colspan;
        tcs += colspan;
        return {
          ...f,
          hidden: expand ? false : showFieldCount < 0,
          colspan: colspan * avgSpan
        };
      });
      return [
        tcs,
        allFields.map((field) => {
          const fp = fieldProps ? fieldProps[field.itemId] || fieldProps[field.name] : null;
          const _field = fp ? {
            ...field,
            ...import_util.iup.isFunction(fp) ? fp(field) : fp
          } : field;
          const hasLabel = !!(showLabel && _field.label);
          return /* @__PURE__ */ React.createElement(import_antd.Col, { span: _field["colspan"], key: _field["name"], hidden: _field["hidden"], style: colStyle }, /* @__PURE__ */ React.createElement(
            import_antd.Form.Item,
            {
              name: _field["name"],
              colon: hasLabel,
              label: /* @__PURE__ */ React.createElement(FiledLabel, { label: hasLabel ? _field["label"] : "" })
            },
            getInput(
              {
                formId,
                field,
                fieldInput,
                fieldProps: fieldProps || {}
              },
              getDisabled(field),
              hasLabel ? "" : _field["label"]
            )
          ));
        })
      ];
    }, [u, memoObj, expand, columns, fieldInput, fieldProps, getDisabled]);
    const clearValues = () => {
      form.setFieldsValue(
        fields.reduce((pre, field) => {
          if (getDisabled(field)) {
            return pre;
          }
          cacheValues[field.name] = void 0;
          if (defaultValues.hasOwnProperty(field.name)) {
            defaultValues[field.name] = void 0;
          }
          return { ...pre, [field.name]: void 0 };
        }, {})
      );
    };
    const locale = props.locale ? import_util.iup.extend(defaultLocale, props.locale) : defaultLocale;
    const querySetting = (0, import_util.useRefCallback)(() => {
      const { width, height } = (0, import_util.getGlobalConfig)().default.helpConfig;
      let refreshType = "";
      const ins = (0, import_functionalComponent.showModal)({
        params: { pageId },
        title: locale.settingTitle,
        width,
        height,
        contentStyle: { padding: "0 5px" },
        content: /* @__PURE__ */ React.createElement(SettingContent, { locale, hiddenTableField }),
        footer: /* @__PURE__ */ React.createElement(SettingFooter, { locale }),
        afterClose: () => {
          if (refreshType) {
            refreshType === "panel" && update({ pageId });
            refreshType === "scheme" && setRefreshScheme({});
          }
          refreshType = "";
        }
      });
      ins.subscribe((type) => {
        refreshType = type;
      }, "updateRefresh");
    });
    const checkChanged = (0, import_util.useRefCallback)(
      (checked) => (0, import_service.setQueryPanelData)({ pageId, checked, values: form.getFieldsValue() })
    );
    (0, import_util.useAsyncEffect)(
      async (ctx) => {
        var _a;
        await (onLoad == null ? void 0 : onLoad(outRef.current));
        (_a = outRef.current._compIns) == null ? void 0 : _a.getObserver().prevNotify({ ins: outRef.current }, "onLoad");
        ctx.isMounted && gridRef && import_util.iup.AllReady(
          () => {
            ctx.isMounted && searchEvent();
          },
          null,
          { delay: false }
        );
      },
      [pageId]
    );
    (0, import_util.useUpdateEffect)(() => {
      gridRef && searchEvent();
    }, [gridRef]);
    (0, import_util.useObjectEffect)(
      () => {
        gridRef && searchEvent();
      },
      values,
      false
    );
    (0, import_util.useUpdateEffect)(() => {
      update({ pageId });
    }, [update, pageId]);
    const handleValuesChange = async (changedValues, allValues) => {
      const res = await (onValuesChange == null ? void 0 : onValuesChange(changedValues, allValues));
      if (res === false) {
        form.setFieldsValue(cacheValues);
      } else if (import_util.iup.isObject(res)) {
        syncValues(res, true);
        form.setFieldsValue(cacheValues);
      } else {
        syncValues(changedValues, true);
      }
    };
    const setting = /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { style: buttonStyle, onClick: querySetting, ...buttonProps }, locale.settingText);
    const buttons = /* @__PURE__ */ React.createElement(import_antd.Row, null, /* @__PURE__ */ React.createElement(import_antd.Col, { span: 24, style: { display: "flex", alignItems: "center" } }, /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { style: buttonStyle, type: "primary", onClick: () => form.submit(), ...buttonProps }, locale.search), /* @__PURE__ */ React.createElement(
      import_functionalComponent.Button,
      {
        style: buttonStyle,
        onClick: () => {
          clearValues();
          onReset == null ? void 0 : onReset(outRef.current);
          form.submit();
        },
        ...buttonProps
      },
      locale.reset
    ), needSetting && !byItems && setting, needRemember && !byItems && /* @__PURE__ */ React.createElement(
      import_baseComponent.Checkbox,
      {
        ref: chk,
        checkedValue: true,
        unCheckedValue: false,
        defaultChecked: queryInfo.isChecked,
        onChange: checkChanged,
        style: { marginLeft: buttonStyle.marginLeft }
      },
      locale.rememberCheckbox
    ), totalColSpan > columns && !showAll && /* @__PURE__ */ React.createElement(
      "a",
      {
        style: { fontSize: 12, marginLeft: buttonStyle.marginLeft },
        onClick: () => {
          setExpand(!expand);
        }
      },
      expand ? locale.up : locale.down,
      /* @__PURE__ */ React.createElement(
        import_icons.DownOutlined,
        {
          style: {
            marginLeft: "0.3em",
            transition: "all 0.3s ease 0s",
            transform: `rotate(${expand ? "180deg" : 0})`
          }
        }
      )
    )));
    if (totalColSpan < 4) {
      return /* @__PURE__ */ React.createElement(
        import_functionalComponent.Panel,
        {
          title: locale.title,
          blankStyle: { flex: "none" },
          headerStyle: { minHeight: 45, height: "auto" },
          extra: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { style: { overflow: "visible", flex: 1, width: 0 } }, /* @__PURE__ */ React.createElement(
            import_antd.Form,
            {
              size,
              form,
              name: memoObj.formId,
              className: "query_search_form",
              style: { padding: 0 },
              onValuesChange: handleValuesChange,
              onFinish
            },
            /* @__PURE__ */ React.createElement(import_antd.Row, { gutter: 24, className: "query_fields query_items", style: { margin: 0, justifyContent: "end" } }, queryFields)
          )), buttons)
        }
      );
    }
    return /* @__PURE__ */ React.createElement(import_functionalComponent.Panel, { title: locale.title, headerStyle: { minHeight: 45, height: "auto" }, extra: buttons }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { style: { overflow: "visible" } }, /* @__PURE__ */ React.createElement(
      import_antd.Form,
      {
        size,
        form,
        name: memoObj.formId,
        className: "query_search_form",
        onValuesChange: handleValuesChange,
        style: { padding: 0 },
        onFinish
      },
      /* @__PURE__ */ React.createElement(import_antd.Row, { gutter: 24, className: "query_fields", style: { margin: "0 -16px -10px -16px" } }, queryFields)
    )));
  },
  "QueryPanel"
);
function QueryFormLoading(columnCount, size) {
  return /* @__PURE__ */ React.createElement(
    "div",
    {
      className: "query_search_form",
      style: { marginBottom: "var(--inner-margin, 16px)", padding: "var(--inner-margin, 16px)" }
    },
    /* @__PURE__ */ React.createElement("div", { className: "skeleton-flex", style: { marginBottom: 10, display: "flex" } }, new Array(columnCount).fill(1).map((v, index) => /* @__PURE__ */ React.createElement(import_antd.Skeleton.Button, { key: index, active: true, size, style: { marginLeft: index === 0 ? 0 : 24 } }))),
    /* @__PURE__ */ React.createElement("div", { style: { display: "flex" } }, /* @__PURE__ */ React.createElement(import_antd.Skeleton.Button, { active: true, style: { width: 32 }, size }), /* @__PURE__ */ React.createElement("div", { style: { flex: 1 } }), /* @__PURE__ */ React.createElement(import_antd.Skeleton.Button, { active: true, size, style: { margin: "0 8px" } }), /* @__PURE__ */ React.createElement(import_antd.Skeleton.Button, { active: true, size }))
  );
}
var QueryPanel = (0, import_react.forwardRef)((props, ref) => {
  const renderForm = (reader, update) => /* @__PURE__ */ React.createElement(
    QueryForm,
    {
      ref,
      ...props,
      id: (props.id || props.pageId || "query").replace(/:/g, "_"),
      reader,
      update
    }
  );
  const cacheData = (0, import_react.useMemo)(() => {
    return {
      fields: props.items,
      values: {},
      isChecked: false
    };
  }, [props.items]);
  if (props.items) {
    const [dataReader, setDataReader] = [
      () => ({
        data: cacheData
      }),
      () => void 0
    ];
    return /* @__PURE__ */ React.createElement("div", { style: { ...props.style } }, renderForm(dataReader, setDataReader));
  }
  return /* @__PURE__ */ React.createElement(AsyncQuery, { props, renderForm });
});
function AsyncQuery({ props, renderForm }) {
  const [dataReader, setDataReader] = (0, import_util.useAsyncSuspense)(
    import_service.getQueryPanelInfo,
    {
      pageId: props.pageId || props.id
    },
    props.pageId || props.id
  );
  (0, import_react.useEffect)(() => {
    var _a, _b, _c;
    const { gridRef } = props;
    const gridIns = import_util.iup.isString(gridRef) ? import_util.iup.getCmp(gridRef) : gridRef == null ? void 0 : gridRef.current;
    (_c = (_b = (_a = gridIns == null ? void 0 : gridIns.getApi) == null ? void 0 : _a.call(gridIns)) == null ? void 0 : _b.startLoading) == null ? void 0 : _c.call(_b);
  }, []);
  return /* @__PURE__ */ React.createElement("div", { style: props.style }, /* @__PURE__ */ React.createElement(import_react.Suspense, { fallback: QueryFormLoading(props.columns || 4, props.size || "default") }, renderForm(dataReader, setDataReader)));
}
function getObjPath(obj, p = []) {
  const prev = p.length > 0 ? p[p.length - 1] : "";
  const tmpKey = Object.keys(obj)[0];
  const tmpValue = tmpKey ? obj[tmpKey] : "";
  const current = [];
  if ((tmpKey == null ? void 0 : tmpKey.indexOf(",")) > 0) {
    tmpKey.split(",").forEach((k) => {
      current.push(prev ? `${prev}.${k}` : k);
    });
  }
  current.push(prev ? `${prev}.${tmpKey}` : tmpKey);
  if (import_util.iup.isObject(tmpValue) && Object.keys(tmpValue).length > 0) {
    return getObjPath(tmpValue, [...p, ...current]);
  }
  return [...p, ...current];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  QueryPanel
});
